import { View } from "../../../../mvc/core/View";
import { EqStrengthEnableBtn } from "./EqStrengthEnableBtn";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { PlayerEqStrengthInfo } from "./PlayerEqStrengthInfo";
import { StrengthAddConfig } from "../../../resource/StrengthAddConfig";
import { EquipTargetType } from "../../../resource/info/EquipTargetType";
import { StrengthenAddInfo } from "../../../resource/info/StrengthenAddInfo";
import { ToolTipInfo } from "../../../model/ToolTipInfo";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { NormalTooltip } from "../../common/tooltip/NormalTooltip";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
type int = number;
//class EquipmentJewelAddPanel
    
    export  class EquipmentJewelAddPanel extends View
    {
        constructor()
        {
            super();
            return;
        }

        public set curCareer(arg1: int)
        {
            this._curCareer = arg1;
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._inited = true;
            if (this._jewelBtn == null) 
            {
                this._jewelBtn = new EqStrengthEnableBtn();
                this._jewelBtn.label = "";
                this._jewelBtn.setSize(33, 28);
                this._jewelBtn.x = 0;
                this._jewelBtn.y = 0;
                this._jewelBtn.styleName = "EquipJewelAddDisableBtn";
                this._jewelBtn.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOverHandler);
                addChild(this._jewelBtn);
                this._ganTxt = ObjCreate.createTextField("Lv.", this._jewelBtn.x + 2, this._jewelBtn.y + 25, 40, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16776960));
                this._jewelTxt = ObjCreate.createTextField("3", this._ganTxt.x + 18, this._jewelBtn.y + 26, 40, 20, this, new GTextFormat(FontUtil.EmbedNumberName, 14, 16776960));
                this._jewelTxt.embedFonts = true;
            }
            return;
        }

        /* internal  */initEnable(): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            this._addInfo = null;
            var loc1=PlayerEqStrengthInfo.getEqJewelTarget(this._mode);
            if (!loc1 || loc1.level == 0 && loc1.amount == 0) 
            {
                this._isEnabled = false;
                this._addInfo = StrengthAddConfig.instance.getLowestAddInfo(EquipTargetType.JewelEmbedTarget, this._curCareer);
                this._jewelBtn.styleName = "EquipJewelAddDisableBtn";
                if (this._addInfo) 
                {
                    this._jewelTxt.text = "" + this._addInfo.level;
                    this._jewelLevel = this._addInfo.level;
                    this._jewelAmount = this._addInfo.amount;
                }
            }
            else 
            {
                this._isEnabled = true;
                this._jewelLevel = loc1.level;
                this._jewelAmount = loc1.amount;
                loc2 = StrengthAddConfig.instance.getAddInfoArray(EquipTargetType.JewelEmbedTarget, this._curCareer);
                loc4 = 0;
                while (loc4 < loc2.length) 
                {
                    loc3 = loc2[loc4] as StrengthenAddInfo;
                    if (loc3.level == loc1.level) 
                    {
                        if (!this._addInfo || loc3.amount <= loc1.amount && (loc3.level > this._addInfo.level || loc3.amount > this._addInfo.amount)) 
                        {
                            this._addInfo = loc3;
                        }
                    }
                    ++loc4;
                }
                this._jewelBtn.styleName = "EquipJewelAddEnableBtn";
                if (this._addInfo) 
                {
                    this._jewelTxt.text = "" + this._addInfo.level;
                }
            }
            this._jewelBtn.drawNow();
            return;
        }

        /* internal  */updateTooltipData(): void
        {
            if (this._jewelBtn && this._addInfo) 
            {
                this._jewelBtn.toolTipData = this.getToolTipData(this._addInfo.level, this._addInfo.amount);
            }
            return;
        }

        /* internal  */getToolTipData(arg1: int, arg2: int): ToolTipInfo
        {
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc9=null;
            var loc10=0;
            var loc11=null;
            var loc12=0;
            var loc13=0;
            var loc14=0;
            var loc15=null;
            var loc1=[];
            var loc2="";
            var loc3=this._curCareer;
            var loc4=PlayerEqStrengthInfo.getEqJewelAmount(arg1, this._mode);
            if (this._addInfo) 
            {
                if (arg1 <= 7) 
                {
                    loc7 = ColorConfig.instance.getItemColorString(3);
                }
                else 
                {
                    loc7 = ColorConfig.instance.getItemColorString(4);
                }
                if (this._isEnabled) 
                {
                    loc2 = (loc2 = loc2 + HTMLUtil.addColor("<font size=\'14\'>" + Language.getStringByParam(61087, this._addInfo.amount, arg1) + "</font>\n", loc7)) + HTMLUtil.addColor(Language.getString(30035) + "\n\n", "#00ff00");
                    loc6 = "#f0ea3f";
                }
                else 
                {
                    loc2 = (loc2 = loc2 + HTMLUtil.addColor("<font size=\'14\'>" + Language.getStringByParam(61071, this._addInfo.amount, arg1, loc4, this._addInfo.amount) + "</font>\n", loc7)) + HTMLUtil.addColor(Language.getString(30036) + "\n\n", "#ff0000");
                    loc6 = "#7c7c7c";
                }
                loc8 = this.getAttributeString(this._addInfo);
                loc2 = loc2 + ("<textFormat leading=\'3\'>" + HTMLUtil.addColor(loc8, loc6) + "<textFormat>\n");
                loc1.push(loc2);
                loc2 = "";
                if (this._isEnabled) 
                {
                    if (!((loc10 = (loc9 = StrengthAddConfig.instance.getAddInfoArray(EquipTargetType.JewelEmbedTarget, loc3)).indexOf(this._addInfo)) == -1) && loc10 + 1 < loc9.length) 
                    {
                        if ((loc11 = loc9[loc10 + 1] as StrengthenAddInfo) && loc11.level <= this._hightLevel) 
                        {
                            if (arg1 != this._lowLevel) 
                            {
                                if (arg1 > this._lowLevel) 
                                {
                                    loc13 = (loc11.level - 1);
                                    loc4 = PlayerEqStrengthInfo.getEqJewelAmount(loc13, this._mode);
                                    loc12 = this._hightAmount;
                                }
                            }
                            else 
                            {
                                loc13 = arg1;
                                loc4 = loc4;
                                loc12 = this._addInfo.amount;
                            }
                            loc7 = loc4 >= loc12 ? "#60e71e" : "#FF0000";
                            loc2 = (loc2 = (loc2 = loc2 + HTMLUtil.addColor(Language.getString(61088) + "\n", "#B1efff")) + HTMLUtil.addColor(Language.getStringByParam(61071, loc12, loc13, loc4, loc12, loc7) + "\n", "#7c7c7c")) + HTMLUtil.addColor(Language.getString(61089) + "\n", "#B1efff");
                            loc14 = PlayerEqStrengthInfo.getEqJewelAmount(loc11.level, this._mode);
                            loc15 = this.getAttributeString(loc11);
                            loc7 = loc14 >= loc11.amount ? "#60e71e" : "#FF0000";
                            loc2 = (loc2 = loc2 + HTMLUtil.addColor(Language.getStringByParam(61072, loc11.amount, loc11.level, loc14, loc11.amount, loc7) + "\n", "#7c7c7c")) + ("<textFormat leading=\'3\'>" + HTMLUtil.addColor(loc15, "#7c7c7c") + "<textFormat>\n");
                            loc1.push(loc2);
                        }
                    }
                    else if (loc10 + 1 >= loc9.length) 
                    {
                        loc2 = HTMLUtil.addColor(Language.getString(60374), "#7c7c7c");
                        loc1.push(loc2);
                    }
                }
                else 
                {
                    loc2 = HTMLUtil.addColor(Language.getStringByParam(61073, this._addInfo.amount, arg1), "#7c7c7c");
                    loc1.push(loc2);
                }
            }
            var loc5;
            return loc5 = new ToolTipInfo(NormalTooltip.ToolTipRenderType_Separate, loc1);
        }

        /* internal  */getAttributeString(arg1: StrengthenAddInfo): string
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc1="";
            var loc5=StrengthAddConfig.instance.getAttributeInfo(arg1);
            var loc6=0;
            while (loc6 < loc5.length) 
            {
                loc2 = loc5[loc6];
                loc3 = loc2["name"] as string;
                loc4 = loc2["value"] as string;
                if (loc3.length != 2) 
                {
                    loc1 = loc1 + ("  " + loc3 + "    " + loc4 + "\n");
                }
                else 
                {
                    loc1 = loc1 + ("  " + loc3 + "            " + loc4 + "\n");
                }
                ++loc6;
            }
            return loc1;
        }

        /* internal  */onMouseOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            if (this._addInfo) 
            {
                loc1.toolTipData = this.getToolTipData(this._addInfo.level, this._addInfo.amount);
            }
            return;
        }

        /* internal  */updateEnable(arg1: Object=null): void
        {
            if (!this._inited) 
            {
                return;
            }
            if (this._mode == GModuleEvent.Mode_Self) 
            {
                this.initEnable();
            }
            return;
        }

        public setOtherEquips(): void
        {
            return;
        }

        public updateAddInfo(): void
        {
            this.initEnable();
            this.updateTooltipData();
            return;
        }

        /* internal */ /* var */_mode: string="自己";

        /* internal */ /* var */_curCareer: int;

        /* internal */ /* var */_jewelBtn: EqStrengthEnableBtn;

        /* internal */ /* var */_jewelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_ganTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_lowLevel: int=4;

        /* internal */ /* var */_hightLevel: int=8;

        /* internal */ /* var */_lowAmount: int=5;

        /* internal */ /* var */_hightAmount: int=39;

        /* internal */ /* var */_addInfo: StrengthenAddInfo;

        /* internal */ /* var */_inited: Boolean=false;

        /* internal */ /* var */_isEnabled: Boolean=false;

        /* internal */ /* var */_jewelLevel: int;

        /* internal */ /* var */_jewelAmount: int;
    }
